package com.ruoyi.project.dict.guhanyuapprove.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.dict.guhanyuapprove.domain.GuhanyuApprove;
import com.ruoyi.project.dict.guhanyuapprove.service.IGuhanyuApproveService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 古汉语审核Controller
 *
 * @author shixiangwen
 * @date 2021-05-19
 */
@Controller
@RequestMapping("/dict/guhanyuapprove")
public class GuhanyuApproveController extends BaseController {
    private String prefix = "dict/guhanyuapprove";

    @Autowired
    private IGuhanyuApproveService guhanyuApproveService;

    @RequiresPermissions("dict:guhanyuapprove:view")
    @GetMapping()
    public String guhanyuapprove() {
        return prefix + "/guhanyuapprove";
    }

    /**
     * 查询古汉语审核列表
     */
    @RequiresPermissions("dict:guhanyuapprove:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GuhanyuApprove guhanyuApprove) {
        startPage();
        List<GuhanyuApprove> list = guhanyuApproveService.selectGuhanyuApproveList(guhanyuApprove);
        return getDataTable(list);
    }

    /**
     * 导出古汉语审核列表
     */
    @RequiresPermissions("dict:guhanyuapprove:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GuhanyuApprove guhanyuApprove) {
        List<GuhanyuApprove> list = guhanyuApproveService.selectGuhanyuApproveList(guhanyuApprove);
        ExcelUtil<GuhanyuApprove> util = new ExcelUtil<GuhanyuApprove>(GuhanyuApprove.class);
        return util.exportExcel(list, "guhanyuapprove");
    }

    /**
     * 新增古汉语审核
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存古汉语审核
     */
    @RequiresPermissions("dict:guhanyuapprove:add")
    @Log(title = "古汉语审核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GuhanyuApprove guhanyuApprove) {
        return toAjax(guhanyuApproveService.insertGuhanyuApprove(guhanyuApprove));
    }

    /**
     * 修改古汉语审核
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        GuhanyuApprove guhanyuApprove = guhanyuApproveService.selectGuhanyuApproveById(id);
        mmap.put("guhanyuApprove", guhanyuApprove);
        return prefix + "/edit";
    }

    /**
     * 修改保存古汉语审核
     */
    @RequiresPermissions("dict:guhanyuapprove:edit")
    @Log(title = "古汉语审核", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GuhanyuApprove guhanyuApprove) {
        return toAjax(guhanyuApproveService.updateGuhanyuApprove(guhanyuApprove));
    }

    @RequiresPermissions("dict:guhanyuapprove:edit")
    @Log(title = "古汉语审核", businessType = BusinessType.UPDATE)
    @PostMapping("/approve")
    @ResponseBody
    public AjaxResult approve(Long id, Integer status) {
        return toAjax(guhanyuApproveService.approve(id, status));
    }


    /**
     * 删除古汉语审核
     */
    @RequiresPermissions("dict:guhanyuapprove:remove")
    @Log(title = "古汉语审核", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(guhanyuApproveService.deleteGuhanyuApproveByIds(ids));
    }
}
